home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
source
/
hobbspr2
/
test.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-21
|
5KB
|
166 lines
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include "hobbes.h"
#include "sprite.h"
#include "tile.h"
void scroll(void);
#define TILE_W 16
#define TILE_H 16
TTileMap testmap(TILE_W,TILE_H,0,0);
#define MAP_W 200
#define MAP_H 200
#define MAP1_W 50
char map1[MAP1_W][MAP_H] = { //25==*
{ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 },
{ 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 },
{ 9, 1, 0, 1, 0, 2, 2, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 0, 5, 5, 0, 0, 6, 0, 0, 6, 0, 1, 1, 1, 0, 2, 2, 2, 2, 2, 9 },
{ 9, 1, 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 5, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 0, 5, 0, 0, 5, 0, 6, 0, 0, 6, 0, 1, 0, 1, 0, 0, 0, 2, 0, 0, 9 },
{ 9, 1, 1, 1, 0, 2, 2, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 5, 0, 0, 0, 0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},
{ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 },
};
#define VIRT_W 400
#define VIRT_H 240
main() {
Set320x240Mode();
SetVirtualPort(VIRT_W,VIRT_H);
SetClipPort(0,0,VIRT_W,VIRT_H);
// SetSplit(220);
// FlipPage();
// testmap.SetMapPort(0,0,VIRT_W,VIRT_H);
for (int i=0; i<256; i++)
testmap.NewTile(i);
for (i=0; i<MAP_W; i++)
for (int j=0; j<MAP_H; j++)
testmap.SetTile(i,j, 0); //map1[j][i]);
char *blah[1] = {"kite2.bit"};
TSprite sprkite(blah,1);
TBitmap kite("kite.bit");
TBitmap tree("tree.bit");
TBitmap ground("ground.bit");
Tile_Handle Hkite = testmap.NewTile(&kite);
Tile_Handle Htree = testmap.NewTile(&tree);
Tile_Handle Hground = testmap.NewTile(&ground);
for(i=0; i<200; i++)
testmap.SetTile(i,8,Hground);
// for(i=0; i<20; i++)
// testmap.SetTile(random(200),8,Htree);
testmap.SetTile(0,8,Htree);
testmap.SetTile(1,8,Htree);
testmap.SetTile(2,8,Htree);
testmap.SetTile(6,8,Htree);
testmap.SetTile(7,8,Htree);
testmap.SetTile(8,8,Htree);
testmap.SetTile(12,8,Htree);
testmap.SetTile(13,8,Htree);
testmap.SetTile(14,8,Htree);
testmap.SetTile(18,8,Htree);
testmap.SetTile(19,8,Htree);
testmap.SetTile(20,8,Htree);
testmap.SetTile(24,8,Htree);
testmap.SetTile(25,8,Htree);
testmap.SetTile(26,8,Htree);
for(i=0; i<30; i++)
testmap.SetTile(random(200),random(8),Hkite);
testmap.SetMapVirtualPort(0,0,VIRT_W,VIRT_H);
testmap.DisplayStart.SetXY(0,0);
testmap.MapLoc.SetXY(10,10);
testmap.DrawWholeMap();
SetMousePort(0,0,10000,500);
MouseInit(10,10,WHITE);
MouseSetCursorShape(UserDef1);
sprkite.SetXY(100,100);
int curmx=MouseX, curmy=MouseY;
while (1) {
if (MouseRightPressed())
break;
sprkite.SetXY(MouseX,MouseY+10);
sprkite.Draw();
scroll();
testmap.Dirty(&sprkite);
}
MouseUnInit();
RestoreTextMode();
return 0;
}
unsigned char readkb(void);
unsigned char readkb()
{
_AH = 0x08;
geninterrupt(0x21); // DOS keyboard interrupt
return _AL;
}
void scroll(void)
{
static int x=0, y = 0, maxx, maxy, dx = 0, dy = 0;
unsigned char c;
int curmx=MouseX,
curmy=MouseY;
// maxx = (Virtual_Width_Pix - Physical_Width_Pix) /4;
// maxy = (Virtual_Height_Pix - Physical_Height_Pix);
// maxx = MAP_W * 20;
// maxy = MAP_H * 20;
maxx = MAP_W * TILE_W;
maxy = MAP_H * TILE_H;
if(kbhit()) {
c = readkb();
if(c == 27) exit(0);
if(c == 0) {
c = readkb();
if(c == 72) dy = -1;
else if(c == 80) dy = 1;
else if(c == 75) dx = -1;
else if(c == 77) dx = 1;
}
else dx = dy = 0;
}
if((x < 1) && (dx == -1)) dx = 0;
if((y < 1) && (dy == -1)) dy = 0;
x += dx;
y += dy;
if(x > maxx) {
x = maxx;
dx = 0;
}
if(y > maxy) {
y = maxy;
dy = 0;
}
if (MouseX-curmx)
testmap.Move(MouseX-curmx);
testmap.Move(dx);
// SetDisplay(x,y);
}